﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DataAccess;
using SPIWareMVVM.ViewModels;

namespace SPIWareMVVM.Views
{
    /// <summary>
    /// Interaction logic for MaterialEdit.xaml
    /// </summary>
    public partial class MaterialEdit : UserControl
    {
        Window1 mainWindow { get; set; }
        ApplicationViewModel applicationViewModel { get; set; }

        public MaterialEdit()
        {
            InitializeComponent();
        }

        protected void PressChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count > 0)
            {
                MachinePress press = (MachinePress)e.AddedItems[0];
                if (press != null)
                {
                    Part part = (Part)this.DataContext;
                    part.PressSize = press.PressSize;
                    part.PressRate = press.PressRate;
                    part.PressOpCost = press.PressOpCost;
                }
            }

        }
        protected void TypeChanged(object sender, SelectionChangedEventArgs e)
        {
            ComboBox list = (ComboBox)sender;
            //mainWindow = (Window1)((DockPanel)list.Parent).Parent;
            mainWindow = (Window1)Window.GetWindow(list);
            if (mainWindow != null) applicationViewModel = (ApplicationViewModel)((ObjectDataProvider)mainWindow.Resources["applicationVM"]).ObjectInstance;

            if (e.AddedItems.Count > 0)
            {
                MaterialType type = (MaterialType)e.AddedItems[0];
                if (type != null)
                {
                    applicationViewModel.SelectedMaterial.MaterialType = type;
                }
            }
        }
    }
}
